// 这个文件就是用于接收前端请求参数
#include <cgic.h>
#include <glib.h>

int cgiMain() 
{
    char gatewayIp[128];
    char location[256];

    // 读取配置信息
    cgiFormString("gatewayIp",gatewayIp,128);
    cgiFormString("location",location,256);    

    // 使用glib把数据保存到ini配置文件中
    // 改造一下，读取配置文件，获取设备文件路径
    GKeyFile *file = g_key_file_new();
    g_key_file_load_from_file(file,"../config/config.ini",G_KEY_FILE_NONE,NULL);
    gchar* path = g_key_file_get_string(file,"config","deviceInfoPath",NULL);


    GKeyFile *keyFile = g_key_file_new();
    g_key_file_set_string(keyFile,"config","gatewayIp",gatewayIp);
    g_key_file_set_string(keyFile,"config","location",location);
    g_key_file_save_to_file(keyFile,path,NULL);
    g_key_file_free(keyFile);
    g_key_file_free(file);


    // 要给前端返回一个操作成功的提示
    cgiHeaderContentType("text/html");
	// 给浏览器响应回一个简单的html网页
	fprintf(cgiOut, "<HTML><HEAD> <meta charset=\"UTF-8\"> \n");
	fprintf(cgiOut, "<TITLE>cgic测试</TITLE></HEAD>\n");
	fprintf(cgiOut, "<BODY><H1>操作成功</H1>\n");
    fprintf(cgiOut,"</BODY></HTML>");
    return 0;
}